package com.tisson.bo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.tisson.dao.AcDepartmentDAO;
import com.tisson.pojo.AcDepartment;

public class DepartmentBO {

	public List findAll(HttpServletRequest request){
		try{
			AcDepartmentDAO dao = new AcDepartmentDAO();
			FilterBO bo = new FilterBO();
			return bo.getDeptList(dao.findAll(), request);
		}catch(Exception e){
			return new ArrayList();
		}
	}
	
	public List search(HttpServletRequest request,String departmentId,String depName,String depAdmin,String depAddress,String depPhone,String logicMark0,String logicMark1,String logicMark2){
		
		try{
			FilterBO bo = new FilterBO();
			AcDepartment department = new AcDepartment();
			List<String> logic = new ArrayList();
			AcDepartmentDAO dao = new AcDepartmentDAO();
			department.setDepartmentId("");
			department.setDepName(depName);
			department.setDepAdmin(depAdmin);
			department.setDepAddress(depAddress);
			department.setDepPhone(depPhone);
			logic.add("AND");
			logic.add(logicMark0);
			logic.add(logicMark1);
			logic.add(logicMark2);
			return bo.getDeptList(dao.search(department,logic), request);
		}catch(Exception e){
			return new ArrayList();
		}
	}
	
	public void delete(AcDepartment department){
		try{
			AcDepartmentDAO dao = new AcDepartmentDAO();
			dao.delete(department);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void add(AcDepartment department){
		try{
			AcDepartmentDAO dao = new AcDepartmentDAO();
			dao.save(department);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public AcDepartment findById(String id){
		try{
			AcDepartmentDAO dao = new AcDepartmentDAO();
			return dao.findById(id);
		}catch(Exception e){
			e.printStackTrace();
			return new AcDepartment();
		}
	}
	
	public void update(AcDepartment department){
		try{
			AcDepartmentDAO dao = new AcDepartmentDAO();
			dao.update(department);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}
